<!DOCTYPE html>
<html lang="zxx">

<head>
    <title>注册界面</title>
    <!-- Meta tag Keywords -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="UTF-8">
    <meta name="keywords" content="注册表单">
    <!-- //Meta tag Keywords -->
    <link href="//fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700;900&display=swap" rel="stylesheet">
    <!-- Style-CSS -->
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <!-- //Style-CSS -->
    <link rel="stylesheet" href="css/font-awesome.min.css" type="text/css" media="all">

    <!-- 前端引入第三方库 jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>

<body>
<!-- form section start -->
<section class="w3l-hotair-form">
    <h1>注册页面</h1> <!-- 表单标题 -->
    <div class="container">
        <!-- form -->
        <div class="workinghny-form-grid">
            <div class="main-hotair">
                <div class="content-wthree">
                    <h2>注册</h2> <!-- 注册标题 -->
                    <form id="registerForm"> <!-- 更新为ID选择器 -->
                        <input type="text" class="text" name="username" placeholder="用户名" required autofocus> <!-- 用户名占位符 -->
                        <input type="password" class="password" name="password" placeholder="密码" required autofocus> <!-- 密码占位符 -->
                        <button class="btn" type="submit">注册</button> <!-- 按钮文本 -->
                    </form>
                    <p class="account">已有账户？ <a href="login.html" id="loginLink">登录</a></p> <!-- 登录提示 -->
                </div>
                <div class="w3l_form align-self">
                    <div class="left_grid_info">
                        <img src="images/1.png" alt="注册图片" class="img-fluid"> <!-- 添加 alt 属性 -->
                    </div>
                </div>
            </div>
        </div>
        <!-- //form -->
    </div>
</section>
<!-- form section start -->

<!-- 添加JavaScript代码 -->
<script>
    $(document).ready(function() {
        // 处理注册表单提交
        $('#registerForm').on('submit', function(event) {
            event.preventDefault(); // 阻止默认表单提交行为

            var username = $('input[name="username"]').val();
            var password = $('input[name="password"]').val();

            $.ajax({
                url: 'http://localhost:8080/Servlet/register',
                method: 'POST',
                data: {
                    username: username,
                    password: password
                },
                success: function(response) {
                    alert('注册成功');
                    // 可以在此处处理成功注册后的逻辑
                    // 例如，重定向到登录页面：
                    window.location.href = 'http://localhost:8080/Servlet/Log_HTML/log.html';
                },
                error: function(response) {
                    alert('注册失败，请重试');
                }
            });
        });
    });
</script>
</body>

</html>
